package br.puc.rio.telas;

import com.vividsolutions.jump.workbench.WorkbenchContext;
import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
import com.vividsolutions.jump.workbench.plugin.PlugInContext;
import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;

public class PlugInUploadFile extends AbstractPlugIn {
	private PlugInContext context;
	private TelaUploadFile telaUploadFile;
	

	public void initialize(PlugInContext context) throws Exception {
		FeatureInstaller featureInstaller = new FeatureInstaller(
				context.getWorkbenchContext());
		featureInstaller.addMainMenuItem(this, // exe
				new String[] {"Fabio Upload"}, // menu path
				"CSV", // aqui vai o titulo do subitem do menu
				false, // checkbox
				null, // icon
				createEnableCheck(context.getWorkbenchContext())); // enable
																	// check
	}

	public static MultiEnableCheck createEnableCheck(
			WorkbenchContext workbenchContext) {
		EnableCheckFactory checkFactory = new EnableCheckFactory(
				workbenchContext);

		return new MultiEnableCheck().add(
				checkFactory.createAtLeastNLayersMustExistCheck(0)) 
				.add(checkFactory.createTaskWindowMustBeActiveCheck());
	}

	public boolean execute(PlugInContext context) throws Exception { 
		this.context = context;
		this.telaUploadFile = new TelaUploadFile(this);
		telaUploadFile.setVisible(true);
		return true;
	}

	public PlugInContext getPlugInContext() {
		return this.context;
	}
}
